export const spheader = {
  orderNum: '',
  projectName: '',
  date: '',
  orgNum: '',
  productModelSpecification: '',
  preNum: '',
  manuNum: '',
  ratedCurrentCheck1: '',
  ratedCurrentCheck2: '',
  ratedCurrentCheck3: '',
  ratedCurrentCheck4: '',
  ratedCurrentCheck5: '',
  ratedCurrentCheck6: '',
  ratedCurrentCheck7: '',
  ratedShortCircuitCheck1: '',
  ratedShortCircuitCheck2: '',
  ratedShortCircuitCheck3: '',
  ratedShortCircuitCheck4: '',
  centerDistCheck1: '',
  centerDistCheck2: '',
  centerDistCheck3: '',
  centerDistCheck4: '',
  customCenterDist: '',
  operatingVoltageCheck1: '',
  operatingVoltageCheck2: '',
  operatingVoltageCheck3: '',
  operatingVoltageCheck4: '',
  storageVoltageCheck1: '',
  storageVoltageCheck2: '',
  storageVoltageCheck3: '',
  storageVoltageCheck4: '',
  configCheck1: '',
  configCheck2: '',
  configCheck3: '',
  configCheck4: '',
  customConfig: ''
}

export const headerFormOrigin = {
  orderNum: '',
  orgNum: '',
  preNum: '',
  manuNum: '',
  centerDist: '',
  projectName: '',
  // orderTemplate: '',
  priority: 3,
  date: '',
  productModelSpecification: '',
  delivery: false,
  type: [],
  // resource: '',
  // desc: '',
  ratedCurrent: '',
  ratedCurrentOptions: [{
    value: '1',
    label: '630A'
  }, {
    value: '2',
    label: '1250A'
  }, {
    value: '3',
    label: '1600A'
  }, {
    value: '4',
    label: '2000A'
  }, {
    value: '5',
    label: '3150A'
  }, {
    value: '6',
    label: '4000A'
  }, {
    value: '7',
    label: '5000A'
  }],
  ratedShortCircuit: '',
  ratedShortCircuitOptions: [{
    value: '1',
    label: '25kA'
  }, {
    value: '2',
    label: '31.5kA'
  }, {
    value: '3',
    label: '40kA'
  }, {
    value: '4',
    label: '50kA'
  }],
  centerDistOptions: [{
    value: '1',
    label: '150mm'
  }, {
    value: '2',
    label: '210mm'
  }, {
    value: '3',
    label: '275mm'
  }],
  operatingVoltage: '',
  operatingVoltageOptions: [{
    value: '1',
    label: 'AC220V'
  }, {
    value: '2',
    label: 'DC220V'
  }, {
    value: '3',
    label: 'AC110V'
  }, {
    value: '4',
    label: 'DC110V'
  }],
  storageVoltage: '',
  storageVoltageOptions: [{
    value: '1',
    label: 'AC220V'
  }, {
    value: '2',
    label: 'DC220V'
  }, {
    value: '3',
    label: 'AC110V'
  }, {
    value: '4',
    label: 'DC110V'
  }],
  config: [],
  configCustom: '',
  configOptions: [{
    value: '1',
    label: '防跳'
  }, {
    value: '2',
    label: '合闸闭锁'
  }, {
    value: '3',
    label: '手车闭锁'
  }]
}

export function handleHeader(cf) {
  const rt = { ...spheader }
  for (const key in rt) {
    if (key in cf) {
      rt[key] = cf[key]
    }
  }
  // handle ratedCurrent
  for (let i = 1; i <= headerFormOrigin.ratedCurrentOptions.length; i++) {
    if (i === parseInt(cf.ratedCurrent)) {
      rt[`ratedCurrentCheck${i}`] = '√'
    } else {
      rt[`ratedCurrentCheck${i}`] = '□'
    }
  }
  // ratedShortCircuit
  for (let i = 1; i <= headerFormOrigin.ratedShortCircuitOptions.length; i++) {
    if (i === parseInt(cf.ratedShortCircuit)) {
      rt[`ratedShortCircuitCheck${i}`] = '√'
    } else {
      rt[`ratedShortCircuitCheck${i}`] = '□'
    }
  }
  // centerDist
  for (let i = 1; i <= headerFormOrigin.storageVoltageOptions.length; i++) {
    if (i === parseInt(cf.storageVoltage)) {
      rt[`storageVoltageCheck${i}`] = '√'
    } else {
      rt[`storageVoltageCheck${i}`] = '□'
    }
  }

  // operatingVoltage
  for (let i = 1; i <= headerFormOrigin.operatingVoltageOptions.length; i++) {
    if (i === parseInt(cf.operatingVoltage)) {
      rt[`operatingVoltageCheck${i}`] = '√'
    } else {
      rt[`operatingVoltageCheck${i}`] = '□'
    }
  }

  // centerDist
  let flag = true
  for (let i = 1; i <= headerFormOrigin.centerDistOptions.length; i++) {
    if (i === parseInt(cf.centerDist)) {
      rt[`centerDistCheck${i}`] = '√'
      flag = false
    } else {
      rt[`centerDistCheck${i}`] = '□'
    }
    if (flag) {
      rt['customCenterDist'] = cf.centerDist
      rt[`centerDistCheck${4}`] = '√'
    } else {
      rt['customCenterDist'] = ''
      rt[`centerDistCheck${4}`] = '□'
    }
  }

  // config
  for (let i = 1; i <= headerFormOrigin.configOptions.length; i++) {
    if (cf.config.includes(i.toString())) {
      rt[`configCheck${i}`] = '√'
    } else {
      rt[`configCheck${i}`] = '□'
    }
    // if (flag) {
    //   rt['customConfig'] = cf.config
    //   rt[`configCheck${4}`] = '√'
    // } else {
    //   rt['customConfig'] = ''
    //   rt[`configCheck${4}`] = '□'
    // }
  }
  rt[`configCheck${4}`] = ''
  rt['customConfig'] = cf.configCustom
  return rt
}

export function reverseHeader(cf) {
  cf = JSON.parse(cf)
  const rt = JSON.parse(JSON.stringify(headerFormOrigin))
  for (const key in rt) {
    if (key in cf) {
      rt[key] = cf[key]
    }
  }
  // handle ratedCurrent
  for (let i = 1; i <= rt.ratedCurrentOptions.length; i++) {
    if (cf[`ratedCurrentCheck${i}`] === '√') {
      rt.ratedCurrent = i.toString()
    }
  }

  // handle ratedShortCircuit
  for (let i = 1; i <= rt.ratedShortCircuitOptions.length; i++) {
    if (cf[`ratedShortCircuitCheck${i}`] === '√') {
      rt.ratedShortCircuit = i.toString()
    }
  }
  // handle operatingVoltageOptions
  for (let i = 1; i <= rt.operatingVoltageOptions.length; i++) {
    if (cf[`operatingVoltageCheck${i}`] === '√') {
      rt.operatingVoltage = i.toString()
    }
  }
  // handle storageVoltage
  for (let i = 1; i <= rt.storageVoltageOptions.length; i++) {
    if (cf[`storageVoltageCheck${i}`] === '√') {
      rt.storageVoltage = i.toString()
    }
  }
  // centerDist
  let flag = true
  for (let i = 1; i <= rt.centerDistOptions.length; i++) {
    if (cf[`centerDistCheck${i}`] === '√') {
      rt.centerDist = i.toString()
      flag = false
    }
  }
  if (flag) {
    rt.centerDist = cf['customCenterDist']
  }
  // config
  rt.config = []
  for (let i = 1; i <= rt.configOptions.length; i++) {
    if (cf[`configCheck${i}`] === '√') {
      rt.config.push(i.toString())
    }
  }
  rt.configCustom = cf['customConfig']
  return rt
}

export const sptail = {
  authorizedStrengthStaff: '',
  checkStaff: '',
  verifyStaff: '',
  version: ''
}

